
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="${pageContext.request.contextPath}/css/common.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        //封装一个查询所有竞拍记录的方法
        function selectAll(){
            $("#recordHead~ul").remove();
            var html = "";
            $.ajax({
                url:"${pageContext.request.contextPath}/record/showAuctionRecord",
                data:"auctionId="+${auction.auctionId},
                dataType:"json",
                success:function (result) {
                    console.log("222");
                    var list = result.show;
                    $(list).each(function (i,obj) {
                        console.log(obj.price);
                        html+='<ul class="rows even border-no">\n' +
                            '        <li>'+obj.time+'</li>\n' +
                            '        <li>'+obj.price+'</li>\n' +
                            '        <li class="borderno">'+obj.user.userName+'</li>\n' +
                            '      </ul>';
                    })
                    $("#showRecord").append(html);
                }
            })
        }
        $(function () {
            selectAll();

            $("#formBut").click(function () {
                var price = $("#sale").val();
                $.ajax({
                    url:"${pageContext.request.contextPath}/record/selectMaxPrice",
                    data:"auctionId="+${auction.auctionId},
                    dataType: "json",
                    success:function (result) {
                        var maxPrice = result.max;
                        if(price>maxPrice){
                            var ar = {
                                "ar.price":price,
                                "ar.user.userId":"${sessionScope.login.userId}",
                                "ar.auction.auctionId":"${auction.auctionId}"
                            }
                            console.log(ar);
                            addRecord(ar);

                        }else{
                            $("#msg").html("不能低于最高竞拍价");
                        }
                    }
                });
            })
        })

        function addRecord(data) {
            $.ajax({
                url:"${pageContext.request.contextPath}/record/addAuctionRecord",
                data:data,
                dataType:"json",
                success:function (result) {
                    var i = result.add;
                    if(i>0){
                        selectAll();
                    }
                }
            })
        }
    </script>
</head>

<body>
<div class="wrap">
    <!-- main begin-->
    <div class="sale">
        <h1 class="lf">在线拍卖系统</h1>
        <div class="logout left">欢迎您：${sessionScope.login.userId} </div>
        <div class="logout right"><a href="${pageContext.request.contextPath}/user/exit" title="注销">注销</a></div>
    </div>
    <div class="items sg-font lf">
        <ul class="rows">
            <li>名称：</li>
            <li class="borderno">${auction.auctionName}</li>
        </ul>
        <ul class="rows">
            <li>描述：</li>
            <li class="borderno">${auction.auctionDesc}</li>
        </ul>
        <ul class="rows">
            <li>开始时间：</li>
            <li class="borderno"><fmt:formatDate value="${auction.auctionStartTime}" pattern="yyyy-MM-dd hh-mm-ss"/> </li>
        </ul>
        <ul class="rows">
            <li>结束时间：</li>
            <li class="borderno"><fmt:formatDate value="${auction.auctionEndTime}" pattern="yyyy-MM-dd hh-mm-ss"/></li>
        </ul>
        <ul class="rows border-no">
            <li>起拍价：</li>
            <li class="borderno">${auction.auctionStartPrice}</li>
        </ul>
    </div>
    <div class="rg borders"><img src="/upload/${auction.auctionPic}" width="270" height="185" alt="" /></div>
    <div class="cl"></div>
    <form id="form" class="top10 salebd">
        <p>
            <label for="sale">出价：</label>
            <input type="text"  class="inputwd" id="sale" value="${auction.auctionStartPrice}"/>
            <input id="formBut" type="button" value="竞 拍" class="spbg buttombg f14  sale-buttom" />
        </p>
        <p class="f14 red"><span id="msg"></span></p>
    </form>
    <div class="top10">
        <input name="" type="submit" value="刷 新" class="spbg buttombg f14" />
        <input name="" type="submit" value="返回列表" class="spbg buttombg f14" />
    </div>
    <div class="offer">
        <h3>出价记录</h3>
        <div id="showRecord" class="items sg-font">
            <ul id="recordHead" class="rows even strong">
                <li>竞拍时间</li>
                <li>竞拍价格</li>
                <li class="borderno">竞拍人</li>
            </ul>

        </div>
    </div>
    <!-- main end-->
</div>
</body>
</html>

